package cst.a307xb.recycleviewtext307xb.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

import cst.a307xb.recycleviewtext307xb.bean.ArticleBean;
import cst.a307xb.recycleviewtext307xb.adapter.MyAdapter;
import cst.a307xb.recycleviewtext307xb.R;

/**
 * Created by dell on 2017/5/15.
 */

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    List<ArticleBean> list;
    private void initRecyclerView(){
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);

        list = getData();
        myAdapter = new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }
    private List<ArticleBean> getData(){
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;

        art = new ArticleBean();
        art.setArticleId(1);
        art.setTitle("标题1");
        art.setImgid(R.drawable.f1);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述1");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(2);
        art.setTitle("标题2");
        art.setImgid(R.drawable.f2);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述2");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(3);
        art.setTitle("标题3");
        art.setImgid(R.drawable.f3);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述3");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(4);
        art.setTitle("标题4");
        art.setImgid(R.drawable.f4);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述4");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(5);
        art.setTitle("标题5");
        art.setImgid(R.drawable.f5);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述5");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(6);
        art.setTitle("标题6");
        art.setImgid(R.drawable.f6);
        art.setTime("2017-5-12 16:43");
        art.setDescription("描述6");
        list.add(art);
        return list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
    }
}
